<?php
/**
* @version		$Id: helper.php 10381 2008-06-01 03:35:53Z pasamio $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

class modcalendarHelper {

	function getCalendar($showtime){
	   
		$db =& JFactory::getDBO();
		if(isset($showtime))
			$time=$showtime;
		else
			$time=time();
		
		$today = getdate($time); 
		$mday = $today ['mday'];
		$mon  = $today ['mon'];   
		$year  = $today ['year'];  

		$time = mktime(0, 0, 0, $mon,1,$year);

		$today = getdate($time); 
		$wday  = $today ['wday'];  
		$year  = $today ['year'];  
		$weekday = $today ['weekday'];
		$month  = $today ['month'];
		$i= -$wday;
		$thisPage=$_SERVER['PHP_SELF'];

		$time = mktime(0, 0, 0, $mon+1,0,$year);
		$lastDay=date('j',$time);
        //$query = 'SELECT * FROM #__phocacalendar WHERE catid in (1,2,3) ORDER BY rand()';
		
		$query = "SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventID FROM #__events WHERE eventDate BETWEEN  '$year/$mon/01' AND '$year/$mon/31'";	

		$db->setQuery( $query );
		$rows = $db->loadObjectList();
		
        return $rows;
		
	}
}